/* CQFS Engine
 * Copyright (c) 2006-2007 Blazing Games Inc. All Rights Reserved
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; 
 * version 2.1 of the License.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package com.blazinggames.cqfsTesting
{

/**
* This holds test results. This breaks tests into three categories:
* Success Tests are tests that are suppose to succeed.
* Failure Tests are tests that are suppose to fail.
* Not Implemented tests are planned tests that have not been written yet most
* likely because the functionality doesn't exist in the classes being tested
* yet.
* There is also a critical failure flag. This is for cases when a unexpected
* failure fails in such a way that it causes an unexpected exception to occur,
* which means that there is at least one critical bug in the code!
* 
* @author Billy D. Spelchan
* @version 1.0
*/
public class TestingResults
{
// *********************
// ***** VARIABLES *****
// *********************
	/** A count of the number of tests that should have succeeded */
	public var successTestsCount:int;
	/** The number of tests that were suppose to succeed that actually did */
	public var successTestsSuccessfull:int;
	
	/** A count of the number of tests that were suppose to fail */
	public var failureTestsCount:int;
	/** A count of the number of tests that were suppose to fail and did */
	public var failureTestsFailing:int;
	
	/** This flag is set if there are critical bugs in the code. */
	public var criticalFailure:Boolean;
	
	/** A count of unimplemented tests so the tester knows more work needed */
	public var testsNotImplemented:int;
	
	/** An array of strings containing details of the tests */
	public var resultsInfo:Array;
	
// ***********************
// ***** CONSTRUCTOR *****
// ***********************

	function TestingResults()
	{
		successTestsCount = 0;
		successTestsSuccessfull = 0;
		failureTestsCount = 0;
		failureTestsFailing = 0;
		criticalFailure = false;
		testsNotImplemented = 0;
		resultsInfo = new Array();
	}

// ****************************************
// ***** Functions - Result reporting *****
// ****************************************

	public function addSuccessTestResult(details:String, success:Boolean):void
	{
		++successTestsCount;
		if (success)
			++successTestsSuccessfull;
		resultsInfo.push(details);
	}
	
	public function addFailureTestResult(details:String, failed:Boolean):void
	{
		++failureTestsCount;
		if (failed)
			++failureTestsFailing;
		resultsInfo.push(details);
	}
	
	public function addNotImplemented(details:String):void
	{
		++testsNotImplemented;
		resultsInfo.push(details);
	}
	
	public function reportCriticalFailure(details:String = "No details on critical failure provided"):void
	{
		criticalFailure = true;
		resultsInfo.push(details);
	}

// ******************************
// ***** Function - getters *****
// ******************************

	public function getSuccessTestsCount():int
	{
		return successTestsCount;
	}
	
	public function getSuccessTestsSuccessfull():int
	{
		return successTestsSuccessfull;
	}
	
	public function getFailureTestsCount():int
	{
		return failureTestsCount;
	}

	public function getFailureTestsFailing():int
	{
		return failureTestsFailing;
	}
	
	public function wasCriticalFailure():Boolean
	{
		return criticalFailure;
	}
	
	public function getTestsNotImplemented():int
	{
		return testsNotImplemented;
	}
	
	public function getResultsInfo():Array
	{
		return resultsInfo;
	}

	public function toString():String
	{
		var results:String = "Test Results:";
		var line:String;
		
		if (criticalFailure)
			results += " A Critical Failure occurred while testing!";
		results += "\nTests for success: ";
		if (successTestsCount < 1)
			results += "No test results to report.";
		else 
			results += (successTestsSuccessfull + " / " + successTestsCount + " (" +
					(successTestsSuccessfull * 100 / successTestsCount) + "%)");
		results += "\nTests for failure: ";
		if (failureTestsCount < 1)
			results += "No test results to report.";
		else 
			results += (failureTestsFailing+ " / " + failureTestsCount + " (" +
					(failureTestsFailing * 100 / failureTestsCount) + "%)");
		results += ("\nTests not implemented: " + testsNotImplemented);
		results += "\nTest details:";
		if (resultsInfo.length < 1)
			results += " No test results to report!";
		else 
			for each (var s:String in resultsInfo) 
				results += ("\n+" + s);
		
		return results;
	}
}// end class
}// end package